Introduction to Matrices
Introduction
Matrices are one of the most useful tools in mathematics. You can think of a matrix as nothing more than a structured way to store numbers—a data table.
If you know basic algebra, you already have everything you need to begin.
What Is a Matrix?
A matrix is a rectangular grid of numbers. For example: $$\begin{pmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \end{pmatrix}$$ Key ideas:
- A matrix has rows (horizontal) and columns (vertical).
- The above matrix has 2 rows and 3 columns.
- We call this a $2 \times 3$ matrix (“2 by 3”).
- Each number inside the matrix is called an entry.
You can think of a matrix as:
- A spreadsheet
- A small table of data
- A way to organize information neatly
Matrices as Data Structures
Matrices are not just mathematical objects—they are containers.
They can store:
- Measurements
- Coordinates
- Relationships
- Transformations
- Any structured numerical data
Examples of matrices as data structures:
- A matrix storing temperatures over several days
- A matrix storing pixel values in an image
- A matrix storing student test scores
Matrices help us:
- Organize data
- Perform operations on entire sets of numbers at once
- Represent systems compactly
Matrix Notation and Terminology
Some gentle notation:
- $A$ usually denotes a matrix.
- $A_{ij}$ means “the entry in row $i$, column $j$.”
- A matrix with $m$ rows and $n$ columns is an $m \times n$ matrix.
Example:
If $$A = \begin{pmatrix} 7 & 8 \\ 9 & 10 \end{pmatrix}$$ Then:
- $A_{11} = 7$
- $A_{12} = 8$
- $A_{21} = 9$
- $A_{22} = 10$
Matrix Addition
You can only add matrices of the same size.
Add them entry‑by‑entry: $$\begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix} + \begin{pmatrix} 5 & 6 \\ 7 & 8 \end{pmatrix} = \begin{pmatrix} 1+5 & 2+6 \\ 3+7 & 4+8 \end{pmatrix} = \begin{pmatrix} 6 & 8 \\ 10 & 12 \end{pmatrix}$$
Scalar Multiplication
Multiply every entry by the same number: $$3 \begin{pmatrix} 2 & 1 \\ 0 & -1 \end{pmatrix} = \begin{pmatrix} 6 & 3 \\ 0 & -3 \end{pmatrix}$$ These operations mirror how you might scale or combine data tables.
Why Matrices Matter
Matrices are everywhere:
- Computer graphics
- Machine learning
- Physics
- Economics
- Engineering
- Statistics
They allow us to:
- Represent large sets of equations
- Transform geometric objects
- Store and manipulate data efficiently
Even at a beginner level, matrices give you a powerful new way to think about information.
Calculator
Matrices as sets of rows
- Matrices can be written literally as a set of rows:
A = [[1, 2], [3, 4]] A = [1, 2, 3; 4, 5, 6]
Matrices from vectors
- We can also create matrices from sets of row or column vectors:
A = matrixFromColumns([1, 2], [3,4]) A = matrixFromRows([1, 2], [3,4])
Matrices from functions
- Instead of defining each value separately, we can specify a function for initializing values.
- The function is run for every entry, and passed the index as it's only parameter.
A = matrixFromFunction(size, fn) A = matrixFromFunction([3,3], f(I) = random()) A = matrixFromFunction([3,3], f(I) = I[1]==I[2] ? 1 : 0)
Matric addition and scalar multiplication
- Addition and scalar multiplication is done like any other data type:
[1, 2; 3, 4] + [5, 6; 7, 8] 5 * [1, 0; 0, 1]
Exercises
- Identify the size (rows and columns) of the matrix $$\begin{pmatrix} 3 & 1 & 4 \\ 1 & 5 & 9 \end{pmatrix}$$
- Compute $$2\begin{pmatrix} 1 & 0 \\ -1 & 3 \end{pmatrix}$$
- Add the matrices $$\begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix} + \begin{pmatrix} 4 & 3 \\ 2 & 1 \end{pmatrix}$$
- True or false: You can add a $2 \times 3$ matrix to a $3 \times 2$ matrix.
- Find the entry in row 2, column 3 of $$\begin{pmatrix} 1 & 4 & 7 \\ 2 & 5 & 8 \\ 3 & 6 & 9 \end{pmatrix}$$
- Multiply the matrix $$\begin{pmatrix} 2 & -1 \\ 0 & 4 \end{pmatrix}$$ by $-3$.
- Describe in words what a matrix is used for.